<?php
/**
 * 
 * @author Radovan Dvorsky
 * @version 20091216
 *
 */
class Zend_View_Helper_DeleteByCheckbox extends Zend_View_Helper_Abstract
{	
	
	public function deleteByCheckbox($clickEvent,$link,$update,$other = null)
    {
        $jquery = $this->view->jQuery();
        $jquery->enable(); // enable jQuery Core Library

        // get current jQuery handler based on noConflict settings
       $jqHandler = ZendX_JQuery_View_Helper_JQuery::getJQueryHandler();		
     	
				
       $function = '("'.$clickEvent.'").click(function(){'
        		  . 'var pidArray = new Array();'
        		  . "var i = 0;"
        		  . '$("input[type=checkbox][:checked]").each('
        		  . 	'function(){'
        		  . 		'if(this.checked == true){'
	        	  . 			'pidArray[i] = this.name;'
	        	  . 			'i++;'
        		  . 		'}'
        		  . 	'});'
        		  . 'if(pidArray.length == 0){'
        		  . 	'alert("Nevybrali ste žiadnu možnosť");'
        		  . 	'return false;'
        		  . '}'
        		  . '$.post("'. $link .'",{id: pidArray.join(),other:"' . $other . '"},function(result){'
        		  . 	'for(var j = 0; j < pidArray.length; j++){	'
        		  . 		'$("tr#" + pidArray[j]).remove().fadeOut("slow");'
        		  . 	'}'
        		  . 	'$("'.$update.'").html(result).fadeIn("slow");'
        		  . 	'});'
        		  . '});';
        		  
        		  

        
        $jquery->addOnload($jqHandler . $function);
        return '';
    }
}